package com.omg.server.framework.ibatis;

public class MySQLDialect implements Dialect{

	private static final String SQL_END_DELIMITER = ";";  


	/** 
     * 去掉当前SQL 后分号 
     * @param sql 
     * @return 
     */  
    private String removeSemiColon(String sql) {
    	if (null == sql){
    	    return "";
    	}
    	
        sql = sql.trim();  
        if (sql.endsWith(SQL_END_DELIMITER)) {  
            sql = sql.substring(0, sql.length() - 1  - SQL_END_DELIMITER.length());  
        }  
        return sql;  
    }

	@Override
	public String getPageSql(String sql, int offset, int limit) {
		StringBuffer buffer = new StringBuffer(sql.length() + 20);
		buffer.append(removeSemiColon(sql));
		buffer.append(" limit ").append(offset).append(",").append(limit);
		buffer.append(SQL_END_DELIMITER);
		return buffer.toString();
	}  

}
